<template>
	<view class="">
		<uni-nav-bar background-color="#fff" color="#000" :status-bar="true" title="活动详情" fixed>

			<view slot="left">
				<view class="navWp">
					<view class="back" @click="goBack">
						<u-icon name="arrow-left" color="#000000" size="50"></u-icon>
					</view>
				</view>
			</view>
		</uni-nav-bar>
		<!-- 活动列表信息 -->
		<view class="active-list">
			<view class="active-info">
				<view class="active-info-img">
					<image class="img-info" :src="activeInfo.image" mode="aspectFill"
						@tap="imagePrview(activeInfo.image)"></image>
				</view>
			</view>
			<view class="active-title-box">
				<view class="active-title">
					<text class="active-text">{{activeInfo.title==null?"":activeInfo.title}}</text>
				</view>
				<view class="active-is-sign">
					<text>发布人: {{activeInfo.name||''}}</text>
				</view>
				<view class="active-is-sign">
					<text>已报名: {{activeInfo.signNumber==null?0:activeInfo.signNumber}}人</text>
				</view>
			</view>

			<view class="active-btm">
				<view class="time-box">
					<img src="https://file.casugn.com/storecompcard//8ZtmYEEYuMwy569f0b4953e7c042dafbd8416ba1301b_1681271289947.png"
						alt="">
					<text>{{activeInfo.startTime==null?"":activeInfo.startTime}}-{{activeInfo.endTime==null?"":activeInfo.endTime}}</text>
				</view>
				<view class="time-box address-box" @click="goToGeo">
					<img src="https://file.casugn.com/storecompcard//Mx1yGAWpNa2A0a3e96f5b6b2f81b87821e36c22a457b_1681271333291.png"
						alt="">
					<text>{{activeInfo.address==null?"":activeInfo.address}}</text>
				</view>
				<view class=" active-content">
					<u-parse :content="activeInfo.content"></u-parse>
				</view>
			</view>

			<view class="sign-number-list">
				<view class="sign-title">
					报名人员名单
				</view>
				<scroll-view :scroll-y="true" style="max-height:400rpx;" @scrolltolower="scrolltolower">
					<view class="sign-item" v-for="(item,index) in signLists" :key="index">
						<view style="margin-right: 20rpx;">
							<u--image v-if="item.head" :src="item.head" width="60rpx" height="60rpx"></u--image>
							<u--image v-else
								src="https://file.casugn.com/storecompcard/temp/avatar_1682582523631.png"
								width="60rpx" height="60rpx"></u--image>
						</view>
						<view class="sign-item-name u-line-1">{{item.name||""}}</view>
						<view class="sign-item-phone" v-if="activeInfo.openId!=userInfo.openId">
							<u-text v-if="item.mobile" size="24rpx" format="encrypt" mode="phone"
								:text="item.mobile"></u-text>
						</view>
						<view class="sign-item-phone" v-else>
							{{item.mobile||""}}
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="sign-box" v-if="activeStatusShow">
				<view class="sign-up" v-if="signSuccess==0?true:false">
					<u-button type="primary" text="报名" @click="signUp"></u-button>
				</view>
				<view class="sign-up" v-if="signSuccess==2?true:false">
					<u-button type="primary" :disabled="true" text="已参加"></u-button>
				</view>
				<view class="cancel-sign-up" v-if="signSuccess==1?true:false">
					<view class="cancel-sign">
						<u-button type="primary" :plain="true" text="取消报名" @click="cancelSignUp"></u-button>
					</view>
					<view class="signed-sign">
						<u-button type="primary" text="已报名" :disabled="true"></u-button>
					</view>
				</view>
			</view>


		</view>

	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				infoId: '',
				avatarList: [],
				// 活动信息列表
				activeInfo: {},
				signSuccess: '',
				activeStatus: '', //0-未开始 1-进行中 2-已结束
				activeStatusText: '', //0-未开始 1-进行中 2-已结束
				activeStatusShow: false, //未开始和已结束 都不能进行操作
				signLists: [],
				pageNo: 1,
				pageSize: 10,
				total: 0
			}
		},
		onLoad(option) {
			this.infoId = option.circleId
			this.activeStatus = option.circleStatus
			if (this.activeStatus == 2) {
				this.activeStatusShow = false
			} else {
				this.activeStatusShow = true
			}
		},
		onShow() {
			uni.setStorageSync(`supplyJumpTo`, 0)
			this.getIsSignLists()
			this.queryListById()

		},
		computed: {
			...mapGetters({
				userInfo: 'userInfo'
			}),
		},
		methods: {
			//拉起导航
			goToGeo() {
				console.log(JSON.parse(this.activeInfo.coord), 'this.activeInfo.coord');
				if (!this.activeInfo.coord) {
					return uni.showToast({
						title: '地址数据有误,无法导航',
						icon: 'none'
					});
				}
				let {
					latitude,
					longitude,
					name,
					address
				} = JSON.parse(this.activeInfo.coord) || {}
				if (latitude && longitude) {
					uni.openLocation({
						latitude: Number(latitude),
						longitude: Number(longitude),
						name: name ? name : '',
						address: address ? address : '',
					});
				} else {
					uni.showToast({
						title: '地址数据有误,无法导航',
						icon: 'none'
					});
				}

			},
			//底部拉取人员
			scrolltolower() {
				this.getIsSignLists('1')
			},
			//预览图片
			imagePrview(url) {
				uni.previewImage({
					urls: [url],
				})
			},
			// 获取已报名名单
			getIsSignLists(more) {
				this.pageNo = more ? ++this.pageNo : 1
				let data = {
					activityId: this.infoId,
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				}
				this.$api.getSignTableLists(data).then(res => {
					console.log(res)
					if (res.success) {
						this.signLists = this.pageNo == 1 ? res.result.records : this.signLists.concat(res.result
							.records)
						this.pageNo = res.result.current
						this.pageSize = res.result.size
						this.total = res.result.total
					}
				})
			},
			goBack() {
				uni.setStorageSync(`supplyJumpTo`, 0)
				const pageNum = getCurrentPages()
				if (pageNum.length > 1) {
					uni.navigateBack()
				} else {
					uni.switchTab({
						url: '/pages/card/card'
					})
				}
			},
			// 根据id获取详情列表
			queryListById() {
				this.$api.getCircleInfoListById(this.infoId).then(res => {
					if (res.success) {
						this.activeInfo = res.result
						this.avatarList = res.result.qzActivitySignVOList
						this.isSign()
					}
				})
			},
			toAttendPerson() {
				if (this.avatarList.length != 0) {
					uni.setStorageSync('signPersonList', JSON.stringify(this.avatarList))
					uni.navigateTo({
						url: '/pagesBusiness/circleList/attendPerson'
					})
				}

			},
			// 获取活动是否报名
			isSign() {
				let openId = uni.getStorageSync('openId')
				console.log("这是openId", openId)
				console.log(this.activeInfo.id)
				let data = {
					openId: openId.openid,
					id: this.activeInfo.id,
				}
				this.$api.signCircleSuccess(data).then(res => {
					this.signSuccess = res.result
					this.getIsSignLists()
				})
			},
			// 报名
			signUp() {
				if (!this.userInfo.id) {
					this.$showToast('请先创建名片,正在跳转...')
					setTimeout(() => {
						uni.navigateTo({
							url: '/pagesCard/createCard/createCard'
						})
					}, 2000)
					return
				}
				let data = {
					openId: this.userInfo.openId,
					cardId: this.userInfo.id,
					id: this.activeInfo.id,
				}
				this.$api.signCircleActive(data).then(res => {
					this.queryListById()
					if (res.success) {
						uni.showToast({
							title: '报名成功',
							icon: 'none'
						});
						this.isSign()
					} else {
						uni.showToast({
							title: '已报名,请勿重复报名！',
							icon: 'none'
						});
					}
				})
			},
			// 取消报名
			cancelSignUp() {
				let data = {
					openId: this.userInfo.openId,
					cardId: this.userInfo.id,
					id: this.activeInfo.id,
				}
				this.$api.cancleSignCircleActive(data).then(res => {
					this.queryListById()
					if (res.success) {
						uni.showToast({
							title: '取消报名成功',
							icon: 'none'
						});
						this.isSign()

					} else {
						uni.showToast({
							title: '已取消报名,请勿重复取消报名！',
							icon: 'none'
						});
					}
				})
			},
		},
		onShareAppMessage() {
			return {
				title: `${this.activeInfo.title?this.activeInfo.title:'活动详情'}`,
				path: `/pagesBusiness/circleList/circleListInfo?circleStatus=${this.activeStatus}&circleId=${this.infoId}`
			}
		}

	}
</script>

<style lang="scss" scoped>
	.active-list {
		background: #F7F8FA;
		position: relative;
		padding-bottom: calc(150rpx + env(safe-area-inset-bottom));

		// 图片
		.active-info {
			background: #FFFFFF;

			.active-info-img {
				margin: 0 auto;
				height: 376upx;
				position: relative;
				overflow: hidden;

				.img-info {
					width: 100%;
					height: 100%;
				}

				.active-info-mask {
					position: absolute;
					width: 690upx;
					height: 70upx;
					bottom: 0;
					background: linear-gradient(0deg, #000000 0%, rgba(0, 0, 0, 0.1000) 100%);
					line-height: 70upx;
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
					text-align: center;
				}
			}
		}

		// 已报名等
		.active-title-box {
			background: #FFFFFF;
			overflow: hidden;
			padding-bottom: 20rpx;

			.active-title {
				font-size: 32rpx;
				font-weight: 600;
				color: #1D2129;
				line-height: 45rpx;
				margin-top: 24rpx;
				margin-left: 32rpx;
				margin-right: 32rpx;
			}

			.active-is-sign {
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #4E5969;
				line-height: 34rpx;
				margin-top: 20rpx;
				margin-left: 32rpx;
				margin-right: 32rpx;
			}
		}

		// 底部内容
		.active-btm {
			margin-top: 24rpx;
			background: #FFFFFF;
			overflow: hidden;
			padding: 0 32rpx 32rpx 32rpx;
			// min-height: 800rpx;

			.time-box {
				display: flex;
				justify-content: flex-start;
				margin-top: 32rpx;

				img {
					width: 32rpx;
					height: 32rpx;
				}

				text {
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #4E5969;
					line-height: 34rpx;
					margin-left: 8rpx;
				}
			}

			.address-box {
				margin-top: 24rpx;
			}

			.active-content {
				margin-top: 24rpx;
			}

		}

		.sign-number-list {
			margin-top: 24rpx;
			padding: 32rpx;
			background: #FFFFFF;

			.sign-title {
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #1D2129;
				line-height: 39rpx;
			}

			.sign-item {
				width: 686rpx;
				height: 98rpx;
				opacity: 1;
				border-bottom: 1rpx solid #E5E6EB;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				line-height: 98rpx;
				font-size: 24rpx;
				font-weight: 400;
				// color: #1D2129;

				.sign-item-phone {
					margin-left: 40rpx;
				}

				.sign-item-name {
					width: 150rpx;
				}
			}
		}

		.active-status {
			position: absolute;
			width: 140upx;
			height: 130upx;
			top: 38upx;
			right: 29upx;

			img {
				width: 140upx;
				height: 130upx;
			}
		}

		.active-head {
			padding: 37upx 0;
			display: flex;
			border-bottom: 1upx solid #EEEEEE;
			letter-spacing: 3upx;

			.head-img {
				width: 72upx;
				height: 72upx;
				border-radius: 50%;

				img {
					width: 72upx;
					height: 72upx;
					margin-top: 1upx;
				}
			}

			.active-name-info {
				margin-left: 21upx;

				.active-name {
					font-size: 30upx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #000000;
				}

				.active-introduce {
					margin-top: 19upx;
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #999999;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					width: 400upx;
				}
			}
		}






		.active-address {
			position: relative;
			height: 110upx;
			line-height: 110upx;
			border-bottom: 1upx solid #EEEEEE;
			// margin-top: 30upx;
			letter-spacing: 3upx;
			display: flex;
			justify-content: space-between;
			align-items: flex-end;

			.active-title {
				border-bottom: none;

				.active-text {
					color: #413BF3;
				}

			}

			.active-address-right {
				position: absolute;
				right: 0;

				.active-address-address {
					font-size: 24upx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #413BF3;
					margin-right: 20upx;
					position: relative;
					top: -2upx;
				}

				img {
					width: 21upx;
					height: 24upx;
				}
			}
		}

		.avatar {
			padding: 37upx;
			flex: 1;
			display: flex;
			justify-content: space-between;
			border-bottom: 1upx solid #EEEEEE;

			.avatar-img {
				img {
					border-radius: 50%;
					width: 60upx;
					height: 60upx;
					margin: 0 -15upx;
				}
			}

			.avatar-num {
				font-size: 24upx;
				font-family: PingFang SC;
				line-height: 60upx;
				font-weight: 400;
				color: #413BF3;

				.avatar-num-right {
					margin-right: 10upx;
				}

			}

		}

		.sign-box {
			position: fixed;
			width: 100%;
			height: 120rpx;
			background: #FFFFFF;
			bottom: 0;
			padding-bottom: 40rpx;
		}

		.sign-up {
			width: 90%;
			margin: 0 auto;
			margin-top: 16rpx;
		}

		.cancel-sign-up {
			display: flex;
			justify-content: space-around;
			margin: 0 auto;
			margin-top: 16rpx;
			// background: red;

			.cancel-sign {
				width: 242upx;
			}

			.signed-sign {
				width: 418upx;
				margin-left: 30upx;
			}
		}
	}
</style>